import json


# with open('info.json', encoding='utf-8') as f:
#     buf = json.load(f)
#     print(type(buf))
#     # print(buf)
#
#     print(buf['name'])
#     print(buf['age'])
#     print(buf['address']['city'])

# with open('info2.json',encoding='utf-8') as f:
#     data = json.load(f)
#     for i in data:
#         print(f'姓名:{i['name']},年龄:{i['age']},性别:{i['sex']},城市{i['address']['city']}')

#
# json 文件保存

# info = {'name': '小明',
#         'age': 22,
#         'sex': '男'
#         }
# with open('info3.json', 'w', encoding='utf-8') as f:
#     # json.dump(info,f)
#     # json.dump(info, f, ensure_ascii=False)  # 中文显示
#     json.dump(info, f, indent=4, ensure_ascii=False)  # 格式化中文显示
# my_dict = {'name': 'isaac', 'age': 23, 'like': ['学习', '游戏']}
# with open('test.json', 'w', encoding='utf-8') as f:
#     json.dump(my_dict, f, ensure_ascii=False,indent=4)
# with open('info4.json', 'r', encoding='utf-8') as f:
#     data = json.load(f)
#     print(f"姓名：{data['name']},爱好：{data['like']}")

# import random
# list1 = []
# for a in range(10):
#     b = random.randint(1, 100)
#     list1.append(b)
#     list1.sort(reverse = True)
# print(list1)
# with open('data.json', 'w',encoding='utf-8') as f:
#     json.dump(list1, f, ensure_ascii=False, indent=4)
#     # print(list1)
#
# list2 = list1[:5]
# with open('data2.json','w',encoding='utf-8') as f:
#     json.dump(list2, f, ensure_ascii=False, indent=4)
def build():
    with open('info5.json', 'r', encoding='utf-8') as f:
        data_list = json.load(f)
        new_list = []
        for i in data_list:
            username = i['username']
            password = i['password']
            code = i['code']
            expect = i['expect']
            a = (username, password, code, expect)
            new_list.append(a)

    return new_list
